package HomeWork2;


import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.FileWriter;

//有五个学生，每个学生有3门课的成绩，从键盘输入以上数据（包括学生号，姓名，三门课成绩），计算出平均成绩，
// 把原有的数据和计算出的平均数存放在磁盘D盘下的”student”文件中。
public class d031HomeWork {
    public static void main(String[] args) throws Exception {
        ChengJi r[]=new ChengJi[5];
        Scanner sc = new Scanner(System.in);
        FileWriter fw = new FileWriter("D:/student.txt");
        BufferedWriter bw = new BufferedWriter(fw);
        for (int i = 0; i < 5; i++) {
            System.out.println("请录入第" + (i + 1) + "名学生的信息");

            int num = sc.nextInt();
            String name = sc.next();
            int result1 = sc.nextInt();
            int result2 = sc.nextInt();
            int result3 = sc.nextInt();

            r[i]=new ChengJi(num, name, result1, result2, result3);
            bw.write( new ChengJi(num, name, result1, result2, result3).toString());
            bw.flush();
            bw.newLine();
        }

        for (int i = 0; i <r.length ; i++) {
            r[i].show();
        }
        System.out.println("已打印到D：/student.txt");
    }
}


class ChengJi{
    int IdNum=0;
    String StName=null;
    int Result1=0;
    int Result2=0;
    int Result3=0;

    public ChengJi(int IdNum, String StName, int Result1,int Result2,int Result3) {
        this.IdNum = IdNum;
        this.StName = StName;
        this.Result1 = Result1;
        this.Result2=Result2;
        this.Result3=Result3;
    }
    void show(){
        System.out.println("学号:"+IdNum+" 姓名:"+StName+" 成绩："+Result1+" "+Result2+" "+Result3+"  平均分："+((Result1+Result2+Result3)/3));
    }

    @Override
    public String toString() {
        return  IdNum+" "+ StName +" "+  Result1 +" "+ Result2 +" "+  Result3
                +" "+(Result1+Result2+Result3)/3;
    }

}